package Model;

public class Preprocessor {

    private DataSet dataSet;
	
	public Preprocessor( DataSet D){
		dataSet=D;
		
    }
    
    public void set3DCoords(Clusterization clus){
        ACPMatrix acpmatrix = new ACPMatrix(dataSet,clus);
		Action action;
		
		acpmatrix.reduit();
		acpmatrix.matrix_propre();
  
		float[][] array = acpmatrix.getEspaceDim3();

		
		for (int i=0 ; i < dataSet.getActionNbr(); i++)
		{
			dataSet.getAction(i).setCoords(array[i]);
		}
        
        for (int i=0 ; i < clus.getClusterNbr(); i++)
		{
			clus.getCluster(i).getCentroid().setCoords(array[dataSet.getActionNbr()+i]);
		}

	}

    public void normalize(){
        int attrNbr=dataSet.getAttributeNbr();
        
        for(int i=0;i<attrNbr;i++){
            if(dataSet.getAttributeType(i)==AttributeType.Numerical){
                float normalizedValue;
                float normParam=NormalizeParameter(dataSet.getAttribute(i));
                float minVal=dataSet.getMinVal(dataSet.getAttribute(i));

                for(int j=0;j<dataSet.getActionNbr();j++){
                    normalizedValue=(Float) dataSet.getValue(j,dataSet.getAttribute(i));
                    normalizedValue=normalizedValue-minVal;
                    normalizedValue=normalizedValue/normParam;
                    dataSet.setNormalizedValue(j, dataSet.getAttribute(i), normalizedValue);

                }
            }
            else{
                for(int j=0;j<dataSet.getActionNbr();j++){
                    dataSet.setNormalizedValue(j, dataSet.getAttribute(i), dataSet.getValue(j,dataSet.getAttribute(i)));
                }
            }
        }
    }

    private float NormalizeParameter(Attribute attribute) {
        if(dataSet.getAttributeType(attribute)==AttributeType.TextualDiscreet){
            return 1;
        }
        else{
            float ecart=dataSet.getMaxVal(attribute)-dataSet.getMinVal(attribute);
            return ecart/100;
        }
    }
	
}
